/*
* name;
*/
class GYSprite extends Laya.Sprite{
    public static _pt:Laya.Point = new Laya.Point;
    public top:number;
    public left:number;
    public bottom:number;
    public right:number;
    public verticalCenter:number;
    public horizonalCenter:number;
    public percentWidth:number;
    public percentHeight:number;
    public disposed:boolean;
    private _disabled:boolean;
    private _grayColor:Laya.ColorFilter;
    constructor(){
        super();
        let s= this;
        s.top = s.left = s.right = s.bottom= s.verticalCenter = s.horizonalCenter = s.percentHeight = s.percentWidth = NaN;
        s._grayColor = new Laya.ColorFilter([
                0.3086, 0.6094, 0.0820, 0, 0,  //R
                0.3086, 0.6094, 0.0820, 0, 0, //G
                0.3086, 0.6094, 0.0820, 0, 0,  //B
                0, 0, 0, 1, 0, //A
            ]);
    }
    /**刷新相对布局*/
    public layout():void
    {var s = this;
        let pr:Laya.Sprite;
        pr = <Laya.Sprite>s.parent;
        if(s.parent == null)
            return;			
        if(s.top == s.top && s.bottom == s.bottom)				
                s.height=pr.height - s.top - s.bottom;				
            if(s.left == s.left && s.right == s.right)
                s.width=pr.width - s.left - s.right;

            if(s.top == s.top)
            {
                s.y=s.top;					
            }
            else if(s.bottom == s.bottom)
            {
                s.y=pr.height - s.height - s.bottom;
            }			
            else if(s.verticalCenter == s.verticalCenter)
            {
                s.y=(pr.height - s.height>>1)+s.verticalCenter;
            }
            if(s.left == s.left)
            {
                s.x=s.left;					
            }
            else if(s.right == s.right)
            {
                s.x=pr.width - s.width - s.right;
            }			
            else if(s.horizonalCenter == s.horizonalCenter)
            {
                s.x=(pr.width - s.width>>1)+s.horizonalCenter;
            }	
    }
    /**刷新相对大小*/
    public sizeChange():void
    {var s = this;
        let pr:Laya.Sprite;
        pr = <Laya.Sprite>s.parent;
        if(s.parent == null)
            return;			
        if(s.percentWidth == s.percentWidth)
        {
            s.width=pr.width * s.percentWidth;
        }			
        if(s.percentHeight == s.percentHeight)
        {
            s.height=pr.height * s.percentHeight;
        }
    }
    /**@ts-ignore*/
    public set width(val:number)
    {
        Laya.superSet(GYSprite,this, "width", val);
    }
    /**@ts-ignore*/
    public get width():number
    {
        let s= this;
        if(s._width == 0 && s.texture)
            return s.texture.sourceWidth;
        return Laya.superGet(GYSprite,this, "width");
    }
    /**@ts-ignore*/
    public set height(val:number)
    {
        Laya.superSet(GYSprite,this, "height", val);
    }
    /**@ts-ignore*/
    public get height():number
    {
        let s= this;
        if(s._height == 0 && s.texture)
            return s.texture.sourceHeight;
        return Laya.superGet(GYSprite,this, "height");
    }
    public dispose(destroyChild: boolean=true):void
    {
        if(this.disposed)return;
        this.disposed = true;
        this.destroy();
    }
    public set disabled(val:boolean)
    {
        let s= this;
        if(s._disabled == val)
            return;
        s._disabled = val;
        s.mouseEnabled = !s._disabled;
        if(s._disabled)
        {
            if(s.filters)
                s.filters.push(s._grayColor);
            else
                s.filters = [s._grayColor];
        }
        else
        {
            if(s.filters && s.filters.length > 0)
            {
                if(s.filters.length == 1 && s.filters[0] == s._grayColor)
                    s.filters = null;
                else
                {
                    let ind:number = s.filters.indexOf(s._grayColor);
                    s.filters.splice(ind, 1);
                    s.filters = s.filters;
                }                
            }
        }        
    }
}